from qiniu import Auth, put_file, etag
access_key = 'xxdTwX3v2X1c8ml-xwFD7saUIW3fWALhoQuByre-'
secret_key = '-LoCyCeUJOOUIuAqm4ncbMn-5onjgBCyzCoTVpbm'
bucket_name = 'pythons'
q = Auth(access_key, secret_key)

# url 图片
# key 上传后保存的文件名
def upload_qiniu(url, key):
    token = q.upload_token(bucket_name, key, 3600)
    ret, info = put_file(token, key, url)
    print(info)
    assert ret['key'] == key
    assert ret['hash'] == etag(url)